
import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author Karthik T
 */

public class splashScreen extends Canvas implements Runnable{
    Image image = null;
    MobilePong parent;
    private boolean running = true;


    public splashScreen(MobilePong parent){
        this.parent=parent;
        try{
            this.image = Image.createImage("/mobilepong.png");
            new Thread(this).start();
            setFullScreenMode(true);
        }catch(Exception e){
        e.printStackTrace();
        }
    }

    public void run(){
        try{
            //while (running){
                repaint();
                try {
        
                    Thread.sleep(2000);
       
                }
                catch (InterruptedException ex) {
                    ex.printStackTrace();
                }
        
            //}
            parent.startMenu();
        }
        catch (Exception e)
        {
        System.out.println("App exception: " + e);
        e.printStackTrace();
        }


    }

    protected void paint(Graphics g){
        g.setColor(0xffffff);
        g.fillRect(0, 0, getWidth(), getHeight());

        if(image != null){
            g.drawImage(image, getWidth() / 2, getHeight() / 2, Graphics.HCENTER| Graphics.VCENTER);
            g.drawString("Press any key", getWidth() / 2, getHeight() - 18 * 1,
                        Graphics.HCENTER | Graphics.TOP);



        } else {
            g.setColor(0x000000);
            g.drawString("No image available", getWidth() / 2, getHeight() / 2,Graphics.HCENTER | Graphics.BASELINE);
        }
    }

    protected void keyPressed(int keyCode)
    {
        running = false;
    }


}

